package cn.hackcloud.blog.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    public static final Logger log = LoggerFactory.getLogger(MyMetaObjectHandler.class);

    @Override
    public void insertFill(MetaObject metaObject) {
        log.debug("start insert fill......");
        // 获取到需要被填充的字段值
        this.fillStrategy(metaObject, "createDate", new Date());
        this.fillStrategy(metaObject, "modifyDate", new Date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        setFieldValByName("modifyDate", new Date(), metaObject);
    }

}
